import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["__id", "_status"],
    _excluded2 = ["__id", "_status"];

/**
 * 客户化管理-DS
 * @since 2019-12-18
 */
import intl from 'utils/intl';
import { CPAAS_IAM } from 'utils/config';
import { filterNullValueObject } from 'utils/utils'; // 共有的from字段

var fromFields = [{
  name: 'customPointCode',
  type: 'string',
  label: intl.get('ciam.customerManage.model.customerManage.customPointCode').d('端点编码')
}, {
  name: 'description',
  type: 'string',
  label: intl.get('ciam.customerManage.model.customerManage.description').d('描述')
}, {
  name: 'className',
  type: 'string',
  label: intl.get('ciam.customerManage.model.customerManage.className').d('类名')
}, {
  name: 'methodName',
  type: 'string',
  label: intl.get('ciam.customerManage.model.customerManage.methodName').d('方法名')
}, {
  name: 'serviceNameLov',
  type: 'object',
  lovCode: 'CADM.SERVICE_CODE',
  label: intl.get('ciam.customerManage.model.customerManage.serviceName').d('服务'),
  ignore: 'always',
  noCache: true
}, {
  name: 'serviceName',
  type: 'string',
  bind: 'serviceNameLov.serviceName'
}]; // 共有的table字段

var tableFields = [{
  name: 'customPointCode',
  type: 'string',
  label: intl.get('ciam.customerManage.model.customerManage.customPointCode').d('端点编码')
}, {
  name: 'priority',
  type: 'number',
  required: true,
  max: 2147483647,
  label: intl.get('ciam.customerManage.model.customerManage.priority').d('优先级')
}, {
  name: 'description',
  type: 'intl',
  required: true,
  maxLength: 480,
  label: intl.get('ciam.customerManage.model.customerManage.description').d('描述')
}, {
  name: 'className',
  type: 'string',
  label: intl.get('ciam.customerManage.model.customerManage.className').d('类名')
}, {
  name: 'methodName',
  type: 'string',
  label: intl.get('ciam.customerManage.model.customerManage.methodName').d('方法名')
}, {
  name: 'serviceName',
  type: 'string',
  label: intl.get('ciam.customerManage.model.customerManage.serviceName').d('服务')
}]; // 查询from

var formDS = {
  fields: fromFields
}; // 管理化table DS

function tableDS(formRecord) {
  return {
    dataKey: 'content',
    cacheSelection: true,
    fields: tableFields,
    events: {
      query: function query(_ref) {
        var dataSet = _ref.dataSet;
        dataSet.unSelectAll();
        dataSet.clearCachedSelected();
      }
    },
    transport: {
      read: function read(config) {
        var params = config.params;
        var url = "".concat(CPAAS_IAM, "/v1/tenant-custom/points");
        var data = {};

        if (formRecord.toData()[0]) {
          var _formRecord$toData$ = formRecord.toData()[0],
              _formRecord$toData$$c = _formRecord$toData$.customPointCode,
              customPointCode = _formRecord$toData$$c === void 0 ? '' : _formRecord$toData$$c,
              _formRecord$toData$$p = _formRecord$toData$.priority,
              priority = _formRecord$toData$$p === void 0 ? '' : _formRecord$toData$$p,
              _formRecord$toData$$s = _formRecord$toData$.serviceName,
              serviceName = _formRecord$toData$$s === void 0 ? '' : _formRecord$toData$$s,
              _formRecord$toData$$d = _formRecord$toData$.description,
              description = _formRecord$toData$$d === void 0 ? '' : _formRecord$toData$$d,
              _formRecord$toData$$c2 = _formRecord$toData$.className,
              className = _formRecord$toData$$c2 === void 0 ? '' : _formRecord$toData$$c2,
              _formRecord$toData$$m = _formRecord$toData$.methodName,
              methodName = _formRecord$toData$$m === void 0 ? '' : _formRecord$toData$$m;
          data = filterNullValueObject({
            customPointCode: customPointCode,
            priority: priority,
            serviceName: serviceName,
            description: description,
            className: className,
            methodName: methodName
          });
        }

        return {
          data: data,
          params: params,
          url: url,
          method: 'GET'
        };
      },
      update: function update(config) {
        var _ref2 = Array.isArray(config.data) ? config.data[0] : {},
            __id = _ref2.__id,
            _status = _ref2._status,
            other = _objectWithoutProperties(_ref2, _excluded);

        return _objectSpread(_objectSpread({}, config), {}, {
          data: other,
          url: "".concat(CPAAS_IAM, "/v1/tenant-custom/points"),
          method: 'PUT'
        });
      },
      destroy: function destroy(config) {
        var _config$params = config.params,
            params = _config$params === void 0 ? {} : _config$params,
            _config$data = config.data,
            data = _config$data === void 0 ? [] : _config$data;
        return {
          data: data,
          params: params,
          url: "".concat(CPAAS_IAM, "/v1/tenant-custom/points"),
          method: 'DELETE'
        };
      }
    }
  };
}

var tenantDS = {
  autoQuery: true,
  dataKey: 'content',
  cacheSelection: true,
  queryFields: [{
    name: 'tenantNum',
    type: 'string',
    label: intl.get('ciam.customerManage.model.customerManage.tenantNum').d('租户编码'),
    unique: true
  }, {
    name: 'tenantName',
    type: 'string',
    label: intl.get('ciam.customerManage.model.customerManage.tenantName').d('租户名称'),
    unique: true
  }],
  fields: [{
    name: 'tenantId',
    type: 'number',
    label: intl.get('ciam.customerManage.model.customerManage.tenantId').d('租户id'),
    unique: true
  }, {
    name: 'tenantNum',
    type: 'string',
    label: intl.get('ciam.customerManage.model.customerManage.tenantNum').d('租户编码'),
    unique: true
  }, {
    name: 'tenantName',
    type: 'string',
    label: intl.get('ciam.customerManage.model.customerManage.tenantName').d('租户名称'),
    unique: true
  }],
  events: {
    query: function query(_ref3) {
      var dataSet = _ref3.dataSet;
      dataSet.unSelectAll();
      dataSet.clearCachedSelected();
    }
  },
  transport: {
    read: function read(config) {
      var url = "".concat(CPAAS_IAM, "/v1/tenants");
      return _objectSpread(_objectSpread({}, config), {}, {
        url: url,
        method: 'GET'
      });
    }
  }
}; // 租户客户化管理查询form

var tenantFormDS = {
  fields: [{
    name: 'tenantIdLov',
    type: 'object',
    lovCode: 'CPFM.TENANT',
    label: intl.get('ciam.customerManage.model.customerManage.tenant').d('租户'),
    noCache: true,
    ignore: 'always'
  }, {
    name: 'tenantName',
    type: 'string',
    bind: 'tenantIdLov.tenantName'
  }, {
    name: 'tenantId',
    type: 'string',
    bind: 'tenantIdLov.tenantId'
  }].concat(fromFields)
}; // 租户客户化管理表格DS

function tenantTableDS(record) {
  return {
    dataKey: 'content',
    cacheSelection: true,
    fields: [{
      name: 'tenantName',
      type: 'string',
      label: intl.get('ciam.customerManage.model.customerManage.tenantName').d('租户名称')
    }].concat(tableFields),
    events: {
      query: function query(_ref4) {
        var dataSet = _ref4.dataSet;
        dataSet.unSelectAll();
        dataSet.clearCachedSelected();
      }
    },
    transport: {
      read: function read(config) {
        var url = "".concat(CPAAS_IAM, "/v1/tenant-custom/points/tenant");
        var params = config.params;
        var data = {};

        if (record.toData()[0]) {
          var _record$toData$ = record.toData()[0],
              _record$toData$$tenan = _record$toData$.tenantId,
              tenantId = _record$toData$$tenan === void 0 ? '' : _record$toData$$tenan,
              _record$toData$$custo = _record$toData$.customPointCode,
              customPointCode = _record$toData$$custo === void 0 ? '' : _record$toData$$custo,
              _record$toData$$prior = _record$toData$.priority,
              priority = _record$toData$$prior === void 0 ? '' : _record$toData$$prior,
              _record$toData$$servi = _record$toData$.serviceName,
              serviceName = _record$toData$$servi === void 0 ? '' : _record$toData$$servi,
              _record$toData$$descr = _record$toData$.description,
              description = _record$toData$$descr === void 0 ? '' : _record$toData$$descr,
              _record$toData$$class = _record$toData$.className,
              className = _record$toData$$class === void 0 ? '' : _record$toData$$class,
              _record$toData$$metho = _record$toData$.methodName,
              methodName = _record$toData$$metho === void 0 ? '' : _record$toData$$metho;
          data = filterNullValueObject({
            tenantId: tenantId,
            customPointCode: customPointCode,
            priority: priority,
            serviceName: serviceName,
            description: description,
            className: className,
            methodName: methodName
          });
        }

        return {
          data: data,
          params: params,
          url: url,
          method: 'GET'
        };
      },
      destroy: function destroy(config) {
        var url = "".concat(CPAAS_IAM, "/v1/tenant-custom/points/revoke");
        var _config$params2 = config.params,
            params = _config$params2 === void 0 ? {} : _config$params2,
            _config$data2 = config.data,
            data = _config$data2 === void 0 ? [] : _config$data2;
        return {
          data: data,
          params: params,
          url: url,
          method: 'DELETE'
        };
      }
    }
  };
} // 刷新客户化表单DS


var refreshDS = {
  autoQueryAfterSubmit: false,
  fields: [{
    name: 'serviceLov',
    label: intl.get('ciam.customerManage.model.customerManage.refreshServiceName').d('服务名'),
    required: true,
    type: 'object',
    ignore: 'always',
    noCache: true,
    lovCode: 'CADM.SERVICE'
  }, {
    name: 'serviceName',
    type: 'string',
    bind: 'serviceLov.serviceCode'
  }, {
    name: 'metaVersion',
    label: intl.get('ciam.customerManage.model.customerManage.metaVersion').d('服务标记版本'),
    required: true,
    type: 'string'
  }, {
    name: 'cleanPermission',
    label: intl.get('ciam.customerManage.model.customerManage.cleanPermission').d('是否清除过期权限'),
    type: 'boolean',
    defaultValue: false
  }],
  transport: {
    create: function create(_ref5) {
      var data = _ref5.data;

      var _ref6 = Array.isArray(data) ? data[0] : {},
          __id = _ref6.__id,
          _status = _ref6._status,
          other = _objectWithoutProperties(_ref6, _excluded2);

      return {
        url: "".concat(CPAAS_IAM, "/v1/tool/permission/fresh-custom-point"),
        method: 'POST',
        params: other,
        data: {}
      };
    }
  }
};
export { formDS, tableDS, tenantDS, refreshDS, tenantFormDS, tenantTableDS };